package com.device.api.service.impl;



import com.device.api.utils.MqttClientUtil;
import com.device.api.entity.PudongDeviceConfig;
import com.device.api.service.MqttService;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;



@Service
public class MqttServiceImpl implements MqttService {

    @Autowired
    private MqttClientUtil mqttClientUtil;


    @Override
    public void sendMqttMessage(String topic, String payload) {


          mqttClientUtil.publish(topic,payload);






    }

    @Override
    public void sendMessage(PudongDeviceConfig pudongDeviceConfig,String payload) {

        String topic = pudongDeviceConfig.getSnCode()+"/device_control";
        sendMqttMessage(topic,payload);

    }

    @Override
    public void sendAllMessage(String payload) {
        sendMqttMessage("/device_control",payload);
    }


}
